#include <mysql.h>
#include <stdio.h>

int main() {
    MYSQL *conn = mysql_init(NULL);
    if (conn == NULL) {
        printf("mysql_init failed\n");
        return 1;
    }

    // 使用你的密码连接到MySQL
    if (mysql_real_connect(conn, "localhost", "root", "1275279401", "test_db", 0, NULL, 0) == NULL) {
        printf("mysql_real_connect failed: %s\n", mysql_error(conn));
        mysql_close(conn);
        return 1;
    }

    if (mysql_query(conn, "SELECT * FROM students")) {
        printf("Query failed: %s\n", mysql_error(conn));
    } else {
        MYSQL_RES *result = mysql_store_result(conn);
        MYSQL_ROW row;

        printf("ID\tName\tAge\n");
        while ((row = mysql_fetch_row(result))) {
            printf("%s\t%s\t%s\n", row[0], row[1], row[2]);
        }
        mysql_free_result(result);
    }

    mysql_close(conn);
    return 0;
}
